<?php
// +----------------------------------------------------------------------
// | 07FLYSAAS [基于ThinkPHP5.0开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2025-2035 http://www.07fly.xyz
// +----------------------------------------------------------------------
// | Professional because of focus  Persevering because of happiness
// +----------------------------------------------------------------------
// | Author: 开发人生 <goodkfrs@qq.com>
// +----------------------------------------------------------------------


namespace app\plat\logic;

/**
 * 租户逻辑
 */
class TenTenant extends PlatBase
{
    /**
     * 信息
     */
    public function getTenTenantInfo($where = [], $field = true)
    {
        return $this->modelTenTenant->getInfo($where, $field);
    }

    /**
     * 编辑
     */
    public function tenTenantEdit($data = [])
    {
        $url = url('tenTenant');
        $result = $this->modelTenTenant->setInfo($data);
        $result && ten_log('编辑', '编辑租户，name：' . $data['company']);
        return $result ? [RESULT_SUCCESS, '编辑成功', $url] : [RESULT_ERROR, $this->modelTenTenant->getError()];
    }

    //获得租户配置参数
    public function getEmailParam()
    {
        return [
            'mail_username' => '发件人邮箱',
            'mail_realname' => '发件人名称',
            'mail_password' => '密码',
            'mail_smtp' => 'SMTP服务器',
            'mail_port' => '端口',
        ];
    }

    /**
     * 获得租户配置配置信息
     * @return void
     * @author: 开发人生 goodkfrs@qq.com
     * @Time: 2024/2/26 11:20
     */
    public function getTenTenantConfigConf()
    {
        $info = $this->modelTenTenantConfig->getInfo([], true);
        !empty($info['config']) && $info['config'] = json_decode($info['config'], true);
        return $info;
    }

    /**
     * 设置租户配置
     * @return void
     * @author: 开发人生 goodkfrs@qq.com
     * @Time: 2024/2/26 11:20
     */
    public function setTenTenantConfigConf($data = [])
    {
        $where['ten_tenant_id'] = TEN_TENANT_ID;
        $info = $this->modelTenTenantConfig->getInfo($where, true);
        $updata['config'] = json_encode($data['param']);
        if (empty($info)) {
            $result = $this->modelTenTenantConfig->setInfo($updata);
        } else {
            $result = $this->modelTenTenantConfig->updateInfo($where, $updata);
        }
        return $result ? [RESULT_SUCCESS, '操作成功'] : [RESULT_ERROR, $this->modelTenTenantConfigLog->getError()];
    }

}